#include "Tools/ToolMoveObject.h"

using namespace Ogre;
ToolMoveObject::ToolMoveObject(Ogre::Camera *mCam, Ogre::SceneManager *mScMgr, RaySceneQuery* ray)
{
	rayQuery=ray;
	mCamera=mCam;
	objectSelected=false;
	select = new ActionSelectObject(mCam,mScMgr,ray);
	moveCam = new ActionMoveCamera(mCam);
}

ToolMoveObject::~ToolMoveObject(){}

void ToolMoveObject::updateGraphics(const FrameEvent &evt){

	moveCam->updateGraphics(evt);
	if(objectSelected)
		moveObject->updateGraphics(evt);
}

void ToolMoveObject::mouseMoved(const OIS::MouseEvent &evt){
	
	if(objectSelected)
		moveObject->mouseMoved(evt);
	scale->mouseMoved(evt);
	moveCam->mouseMoved(evt);
}

void ToolMoveObject::mousePressed(const OIS::MouseEvent &evt){

	if(!objectSelected){
		if(select->mousePressed(evt)){
			moveObject = select->getActionMoveObject();
			scale = new ActionScaleObject(select->getSelectedNode());
			select->getSelectedNode()->showBoundingBox(true);
			objectSelected=true;
		}
	}
	else{
		moveObject->mousePressed(evt);
		MapEditor::instance()->toolEnded();
		objectSelected=false;
	}	
}

void ToolMoveObject::keyPressed(const OIS::KeyEvent &evt){
	
	moveCam->keyPressed(evt);
}
void ToolMoveObject::keyReleased(const OIS::KeyEvent &e){

	moveCam->keyReleased(e);
}
